import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)







const router = new Router({
  mode: 'history',
  routes: [
    {
      name: 'Login',
      path: '/login',
      component: () => import('../views/Login.vue')
    },
    {
      name: 'ForgotPassword',
      path: '/forgotPassword',
      component: () => import('../views/ForgotPassword.vue')
    }, {
      name: 'Register',
      path: '/register',
      component: () => import('../views/Register.vue')
    },
    {
      name: 'Home',
      path: '/home',
      component: () => import('../views/Home.vue'),
      children: [
        {
          name: 'Console',
          path: '/home',
          component: () => import('../components/Console.vue'),
          children: [
            {
              name: 'Page1',
              path: '/home/console/page1',
              component: () => import('../views/Page1.vue')
            }

          ]
        },
        {
          name: 'Page2',
          path: '/home/page2',
          component: () => import('../views/Page2.vue')
        }
      ]
    }
  ],
  // linkActiveClass: 'active'
})
/*

全局路由钩子

访问资源时需要验证localStorage中是否存在token

以及token是否过期

验证成功可以继续跳转

失败返回登录页重新登录

 */
// const permitAll = ["/login", "/forgotPassword", "/register"];
// router.beforeEach((to, from, next) => {
//   // if (localStorage.access_token && new Date().getTime() < localStorage.tokenExpired) {
//   if (localStorage.access_token && new Date().getTime() < localStorage.expires_in) {
//     if (permitAll.indexOf(to.path) > -1) {
//       next('/home/console')
//     } else if (to.path == "" || to.path == "/" || to.path == "/home" || to.path == "/home.html") {
//       window.location.href = "/door.html"
//     } else {
//       next()
//     }
//   } else {
//     if (permitAll.indexOf(to.path) > -1) {
//       next()
//     } else if (to.path == "" || to.path == "/" || to.path == "/home" || to.path == "/home.html") {
//       window.location.href = "/door.html"
//     } else {
//       next('/login')
//     }
//   }
// })
export default router;